var getCookie = readCookie("user")
$("#myId").val(getCookie)
if(!getCookie){
	location.href="login.htm"
}
getUserInfo()

function getUserInfo(){
	$.ajax({
		url:"http://localhost:8080/user/login",
		type:"post",
		dataType:"json",
		data:{
			"id":getCookie
			},
		async:false,
		success:function(data){
			
			$("#img1").prop("src","http://localhost:8080/"+data.data.img)
		}
	})
}


	function updateUser(){
		
		if(checked1()==true){
			addUser()
		
		}else{
			
			$.DialogByZ.Alert({Title: "提示", Content: "输入数据有误",BtnL:"确定"})
		} 
		
	}
	 function checked1(){
		var tel=$("#tel").val()
		var email=$("#email").val()
		var name1=$("#name").val()
		var u_name=$("#uName").val()
		var temp=0;
		var sex=document.getElementsByName("sex")
		var regEmail=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
		var regTel=/^1(3|4|5|6|7|8|9)\d{9}$/
		 if(regTel.test(tel)){
		} else{
			return false
		}
		if(regEmail.test(email)){
		}else{
			return false
		}
		if(name1){			
		}else{
			return false
		}
		if(u_name){			
		}else{
			return false
		}
		for(var i=0;i<sex.length;i++){
			if(sex[i].checked){
				temp++;
			}
		}
		if(temp==0){
			return false
		}
		return true
	} 
	function addImg(){
	
		$.ajax({
			url:"http://localhost:8080/user/addImg",
			type:"post",
			dataType:"json",
			data:new FormData($("#myForm")[0]),
			contentType:false,
			processData:false,
			async:false,
			success:function(data){
				
				$("#img1").prop("src","http://localhost:8080/"+data.data)
			}
		})
		
	}
	function addUser(){
		
		$.ajax({
			url:"http://localhost:8080/user/updateInfo",
			type:"post",
			dataType:"json",
			data:$("#myForm").serialize(),
			async:false,
			success:function(data){
				$.DialogByZ.Autofade({Content: data.msg})
				
			}
		})
		
	}